package my.service;

//import com.anna.config.Ioc.Service;
//import my.model.User;

//import java.util.List;

import com.anna.config.Ioc.Service;
import my.model.User;

import java.util.List;

/**
 * Created by rajab on 17/4/13.
 */
@Service
public class UserService {
    public enum LoginResult {
        LOGIN_SUCCESS,
        INPUT_INVALID,
        PASSWORD_WRONG,
        USER_NOT_EXIST
    }

    public LoginResult checkLogin(String username, String password) {
        if (username.isEmpty() || password.isEmpty()) {
            return LoginResult.INPUT_INVALID;
        } else {
            List<User> users = User.dao.find("SELECT * FROM user where username=?", username);
            if(users.size()==0)
            {
                return LoginResult.USER_NOT_EXIST;
            }
            else if(users.get(0).getPassword().equals(password))
            {
                return LoginResult.LOGIN_SUCCESS;
            }
            else
            {
                return LoginResult.PASSWORD_WRONG;
            }
        }

    }


    public enum SignResult {
        SIGN_SUCCESS,
        INPUT_INVALID,
        PASSWORD_WRONG,
        USER_EXIST
    }

    public SignResult checkSign(String username, String password) {
        if (username.isEmpty() || password.isEmpty()) {
            return SignResult.INPUT_INVALID;
        } else {
            List<User> users = User.dao.find("SELECT * FROM user where username=?", username);
            if(users.size()!=0)
            {
                return SignResult.USER_EXIST;
            }
            else
            {
                return SignResult.SIGN_SUCCESS;
            }
        }
    }

    //public abstract User createUser(String username, String password, String role);
}
